package util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class LevelReader {

	BufferedReader reader = null;

	public LevelReader() {
		try {
			reader = new BufferedReader(new FileReader("D:\\answer1.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public LevelReader(int map) {
		File f = new File("D:\\vsgame\\solution" + map);
		try {
			reader = new BufferedReader(new FileReader(f));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public List<String> generateAnswer() {

		List<String> answer = new ArrayList<String>();
		try {
			String line = null;
			String firstLine = reader.readLine();
			while ((line = reader.readLine()) != null) {
				if (line.trim().length() == 0)
					continue;
				answer.add("MySystem.println(\"" + line + "\");");
			}
			Collections.shuffle(answer);
			answer.add(0, "MySystem.println(\"" + firstLine + "\");");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return answer;
	}

	public List<String> getAnswer() {

		List<String> answer = new ArrayList<String>();
		try {
			String line = reader.readLine();
			int count = Integer.parseInt(line);
			
			for (int i = 0; i < count; i++) {
				line = reader.readLine();
				if (line.trim().length() == 0)
					continue;
				answer.add(line);
			}
			Collections.shuffle(answer);
			answer.add(0, count + "");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return answer;
	}

	public void close() {
		if (reader != null) {
			try {
				reader.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		LevelReader reader = new LevelReader();
		List<String> answer  = reader.getAnswer();
		for(String s:answer){
			System.out.println(answer);
		}
//		for (int i = 175; i <= 200; i++) {
//			LevelReader reader = new LevelReader(i);
//			System.out.println("public static void a" + i + "(){");
//			for (String str : reader.generateAnswer()) {
//				System.out.println(str);
//			}
//			System.out.println("}");
//			System.out.println();
//		}
	}
}
